package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCouponMapper;
import com.qf.mapper.DtsCouponUserMapper;
import com.qf.pojo.DtsCoupon;
import com.qf.service.DtsCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/25 9:06
 */
@Service
public class DtsCouponServiceImpl implements DtsCouponService {

    @Autowired
    private DtsCouponMapper dtsCouponMapper;
    @Autowired
    private DtsCouponUserMapper dtsCouponUserMapper;

    @Override
    public IPage<DtsCoupon> findListByQuery(String name, Integer goodsType, Integer status, String sort, String order, Integer page, Integer limit) {
        return dtsCouponMapper.selectPage(new Page<DtsCoupon>(page, limit)
                , new QueryWrapper<DtsCoupon>()
                        .like(!StringUtils.isEmpty(name), "name", name)
                        .orderBy(!StringUtils.isEmpty(sort), "ASC".equalsIgnoreCase(order), sort)
        );
    }

    /**
     * 优惠券添加
     * @param dtsCoupon
     * @return
     */
    @Override
    public DtsCoupon create(DtsCoupon dtsCoupon) {
        dtsCouponMapper.insert(dtsCoupon);
        return dtsCoupon;
    }

    /**
     * 优惠券编辑
     * @param dtsCoupon
     * @return
     */
    @Override
    public DtsCoupon update(DtsCoupon dtsCoupon) {
        dtsCouponMapper.updateById(dtsCoupon);
        return dtsCoupon;
    }

    /**
     * 优惠券删除
     * @param dtsCoupon
     * @return
     */
    @Override
    public DtsCoupon delete(DtsCoupon dtsCoupon) {
        dtsCouponMapper.deleteById(dtsCoupon);
        return dtsCoupon;
    }
}
